package rsj.api.test.offline;

import com.rlyy.aibase.utils.base.Box;
import com.rlyy.aibase.utils.base.MapNode;
import com.rlyy.aibase.utils.base.TableNode;
import common.util.BoxUtil;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import rsj.api.user.BaseLink;
import rsj.service.IExecuteInterface;
import common.util.QueryRunnerFactory;

import java.sql.SQLException;

/**
 * 数据录入-查询客户简称下拉
 *
 * @author yuanqinglong
 * @since 2021/3/15 16:21
 */
@RestController
public class OrgNameSelectController extends BaseLink {


    /**
     * 数据录入-查询客户简称下拉
     *
     * @param box 参数
     * @return 客户简称下拉
     * @throws SQLException 异常
     */
    @Override
    @RequestMapping(value = "rsj_add_data_select_org")
    public Box executeLink(Box box) throws SQLException {
        return BoxUtil.successBox(box).putMapNode("data", this.queryOrgNames());
    }


    /**
     * 查询机构下拉列表
     *
     * @return 列表
     */
    private MapNode queryOrgNames() {
        String sql = " SELECT org_manbus ,org_name ,org_id FROM sys.sys_org ";
        TableNode tableNode = (TableNode) IExecuteInterface.doExecuteQuery(connection ->
                        QueryRunnerFactory.getQueryRunner().queryLinkTableNode(connection, sql),
                e -> logger.error("数据录入失败,{}", e));
        return new MapNode().putTableNode("List", tableNode);
    }
}
